﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AccesoDatos;

namespace RMA.Pantallas
{
    public partial class frm_AutorizacionTicket : Form
    {
        DataTable dtUser = null;
        DataTable dtResultados = null;
        string filtro = "";
        public frm_AutorizacionTicket()
        {
            InitializeComponent();
        }
        public frm_AutorizacionTicket(DataTable _dtUser)
        {
            dtUser = _dtUser;
            InitializeComponent();
        }
        Manejador_Autorizacion Manejador = new Manejador_Autorizacion();
        private void frm_AutorizacionTicket_Load(object sender, EventArgs e)
        {
            cmb_suc.DataSource = Manejador.RegresaSucursales();
            cmb_suc.DisplayMember = "nombre";
            cmb_suc.ValueMember = "SucId";           
        }

        private void cmb_suc_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string filtro = cmb_suc.SelectedValue.ToString();
                dataGridView1.DataSource=Manejador.tickets_pendientes(int.Parse(filtro),10);
                RadioButton2.Checked = true;
            }
            catch { }
        }

        private void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton1.Checked == true) 
            {
                dataGridView1.DataSource = null;
                filtro = cmb_suc.SelectedValue.ToString();
                spinningProgress1.Visible = true;
                backgroundWorker1.RunWorkerAsync();
                //string filtro = cmb_suc.SelectedValue.ToString();
                //dataGridView1.DataSource = Manejador.tickets_pendientes(int.Parse(filtro), 0);
            }
        }

        private void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton2.Checked == true)
            {
                dataGridView1.DataSource = null;
                filtro = cmb_suc.SelectedValue.ToString();
                spinningProgress1.Visible = true;
                backgroundWorker1.RunWorkerAsync();
                //filtro = cmb_suc.SelectedValue.ToString();
                //dataGridView1.DataSource = Manejador.tickets_pendientes(int.Parse(filtro), 10);
            }
        }

        private void RadioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton3.Checked == true)
            {
                dataGridView1.DataSource = null;
                filtro = cmb_suc.SelectedValue.ToString();
                spinningProgress1.Visible = true;
                backgroundWorker1.RunWorkerAsync();
                //filtro = cmb_suc.SelectedValue.ToString();
                //dataGridView1.DataSource = Manejador.tickets_pendientes(int.Parse(filtro), 4);
            }
        }

        private void RadioButton4_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton4.Checked == true)
            {
                dataGridView1.DataSource = null;
                filtro = cmb_suc.SelectedValue.ToString();
                spinningProgress1.Visible = true;
                backgroundWorker1.RunWorkerAsync();
                //filtro = cmb_suc.SelectedValue.ToString();
                //dataGridView1.DataSource = Manejador.tickets_pendientes(int.Parse(filtro), 1);
            }
        }

        private void RadioButton5_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton5.Checked == true)
            {
                dataGridView1.DataSource = null;
                filtro = cmb_suc.SelectedValue.ToString();
                spinningProgress1.Visible = true;
                backgroundWorker1.RunWorkerAsync();
                //filtro = cmb_suc.SelectedValue.ToString();
                //dataGridView1.DataSource = Manejador.tickets_pendientes(int.Parse(filtro), 12);
            }
        }

        private void cerrado_CheckedChanged(object sender, EventArgs e)
        {
            if (cerrado.Checked == true)
            {
                dataGridView1.DataSource = null;
                filtro = cmb_suc.SelectedValue.ToString();
                spinningProgress1.Visible = true;
                backgroundWorker1.RunWorkerAsync();
                //filtro = cmb_suc.SelectedValue.ToString();
                //dataGridView1.DataSource = Manejador.tickets_pendientes(int.Parse(filtro), 6);
            }
        }

        private void RadioButton6_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton6.Checked == true)
            {
                dataGridView1.DataSource = null;
                filtro = cmb_suc.SelectedValue.ToString();
                spinningProgress1.Visible = true;
                backgroundWorker1.RunWorkerAsync();
                //filtro = cmb_suc.SelectedValue.ToString();
                //dataGridView1.DataSource = Manejador.tickets_pendientes(int.Parse(filtro), 13);
            }
        }

        private void radioButton7_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton7.Checked == true)
            {
                dataGridView1.DataSource = null;
                filtro = cmb_suc.SelectedValue.ToString();
                spinningProgress1.Visible = true;
                backgroundWorker1.RunWorkerAsync();
                //filtro = cmb_suc.SelectedValue.ToString();
                //dataGridView1.DataSource = Manejador.tickets_pendientes(int.Parse(filtro), 17);
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string fol = dataGridView1.SelectedCells[0].Value.ToString().Trim();
            string fols = dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[1].Value.ToString();
            frm_autorizacion_detalle a = new frm_autorizacion_detalle(fols, dtUser);
            a.ShowDialog();

            if (RadioButton1.Checked == true)
            {
                RadioButton1_CheckedChanged(sender, e);
            }
            if (RadioButton2.Checked == true)
            {
                RadioButton2_CheckedChanged(sender, e);
            }
            if (RadioButton3.Checked == true)
            {
                RadioButton3_CheckedChanged(sender, e);
            }
            if (RadioButton4.Checked == true)
            {
                RadioButton4_CheckedChanged(sender, e);
            }
            if (RadioButton5.Checked == true)
            {
                RadioButton5_CheckedChanged(sender, e);
            }
            if (RadioButton6.Checked == true)
            {
                RadioButton6_CheckedChanged(sender, e);
            }
            if (radioButton7.Checked == true)
            {
                radioButton7_CheckedChanged(sender, e);
            }
            if (cerrado.Checked == true)
            {
                cerrado_CheckedChanged(sender, e);
            }
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            dtResultados = Manejador.tickets_pendientes(int.Parse(filtro), 0);
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            dataGridView1.DataSource = dtResultados;
            spinningProgress1.Visible = false;
        }
    }
}
